/*******************************************************************************
 * Copyright (c) 2002, 2003 Boris Pruessmann and others. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Common Public License v0.5 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation. Boris Pruessmann -
 * Added createGroup.
 ******************************************************************************/
package net.sourceforge.perforce.ui.dialogs;

import net.sourceforge.perforce.ui.internal.Policy;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;

/**
 * @version $Revision: 488 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net">Boris
 *         Pruessmann</a>
 */
final class DialogUtils {

  /** Constructor for DialogUtils. */
  private DialogUtils() {
  }

  /**
   * Called to create a checkbox button.
   * 
   * @param parent the parent composite.
   * @param text the button's text.
   * @return the new Button.
   */
  public static Button createCheckButton(Composite parent, String text) {
    Policy.assertNotNull(parent);
    Policy.assertNotNull(text);

    Button result = new Button(parent, SWT.CHECK);
    result.setText(text);

    return result;
  }

  /**
   * Called to create a new combo within the given parent.
   * 
   * @param parent the parent composite.
   * @param widthHint hint for the combo's width.
   * @return the created Combo.
   */
  public static Combo createCombo(Composite parent, int widthHint) {
    Policy.assertNotNull(parent);

    Combo result = new Combo(parent, SWT.READ_ONLY);
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    data.widthHint = widthHint;
    result.setLayoutData(data);

    return result;
  }

  /**
   * Creates a new composite within the specified parent, having
   * <code>numColumns</code> columns.
   * 
   * @param parent the parent of the composite.
   * @param numColumns number of columns.
   * @return the new Composite.
   */
  public static Composite createComposite(Composite parent, int numColumns) {
    Policy.assertNotNull(parent);

    Composite result = new Composite(parent, SWT.NULL);

    // GridLayout
    GridLayout layout = new GridLayout();
    layout.numColumns = numColumns;
    result.setLayout(layout);

    // GridData
    GridData data = new GridData(GridData.FILL_BOTH);
    result.setLayoutData(data);

    return result;
  }

  /**
   * Creates a new group within the specified parent, having
   * <code>numColumns</code> columns.
   * 
   * @param parent the parent of the composite.
   * @param numColumns number of columns.
   * @return the new Composite.
   */
  public static Group createGroup(Composite parent, int numColumns) {
    Policy.assertNotNull(parent);

    Group result = new Group(parent, SWT.NULL);

    // GridLayout
    GridLayout layout = new GridLayout();
    layout.numColumns = numColumns;
    result.setLayout(layout);

    // GridData
    GridData data = new GridData(GridData.FILL_BOTH);
    result.setLayoutData(data);

    return result;
  }

  /**
   * Called to create a label with the given parent, labels it with the
   * specified text.
   * 
   * @param parent the parent composite.
   * @param text the label's text.
   * @return the Label control.
   */
  public static Label createLabel(Composite parent, String text) {
    Policy.assertNotNull(parent);
    Policy.assertNotNull(text);

    Label result = new Label(parent, SWT.NULL);
    result.setText(text);

    return result;
  }
}
